<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>网页授权</title>
</head>
<body>
<script>
    function get_code() {
        let url = window.location.href;
        if (url.indexOf("code=") > 0) {
            let reg = new RegExp('(^|&)' + 'code' + '=([^&]*)(&|$)')
            let r = window.location.search.substr(1).match(reg)
            let res = decodeURIComponent(r[2])

            let typereg = new RegExp('(^|&)' + 'type' + '=([^&]*)(&|$)');
            let typeR =  window.location.search.substr(1).match(typereg)
            let type = ""
            if(typeR){
                 type = decodeURIComponent(typeR[2])
            }


            if (r != null) {
                console.log("code->",res)
                if(type==='paycar'){
                    window.localStorage.setItem("redirect_url","/pages/oa/pay/pay-car");
                }
                let toUrl = "http://kfzc.chaenggroup.com/wxh5/?code=" + res;
                if(type==='paycar'){
                    toUrl = toUrl + "&path=" + encodeURIComponent("/pages/oa/pay/pay-car")
                }
                console.log(toUrl)
                window.location.href = toUrl
                // window.location.href = "http://zsoah5.gek6.com/h5?code=" + res
                // window.location.href = "http://192.168.254.47:8080/h5?code=" + res
            }
        } else {
            const APPID = "wx360016296b401d98";
            let REDIRECT_URI = encodeURIComponent(window.location.href);
            window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APPID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`;
        }
    }
    get_code();
</script>
</body>
</html>
